3页:控制文字域的值
作者:Thau!
将鼠标滑过该链接看看会发式什么事情。

错误!超级链接引用无效。 错误!超级链接引用无效。

<form name="first_form">

<input type="text" name="first_text" value="Are you happy?">

</form>

改变文字域的链接为:

<a href="#" 
onMouseOver="window.document.first_form.first_text.value='Clap clap!';">
Yes, and I know it.</a>

<a href="#" 
onMouseOver="window.document.first_form.first_text.value='Sour puss!';">
No!</a>
window.document.first_form.first_text.value='Clap clap!'
意思是说,表单调用第1个表单,并将其值设为 'Clap clap!'
2行作用相似。这同改变图象的src非常相似。只不过文字域改变
的是值。

textareas也可以采用类似的方法改变值:

错误!超级链接引用无效。 错误!超级链接引用无效。

<a href="#" 
onMouseOver="window.document.form_two.the_textarea.value=first_part;">
Part 1</a>

<a href="#" 
onMouseOver="window.document.form_two.the_textarea.value=second_part;">
Part 2</a>
唯一的不同之处在于将一个变量赋值给
textareas,而不是将字符串赋值给它。该变量在
HTML首部已经做了定义。以下是变量的字符串赋
值:

var first_part = "Now I'm the king of the swingers\nOh, 
the jungle VIP\nI've reached the top and had to stop\nAnd 
that's what botherin' me";
注意"\n"是换行符。如果你在一个<pre> 并且或在
一个
textarea中写字,"\n" 换行符非常方便。

除了改变表单元素的值,JavaScript还可以让你检
测在表单中进行的事件。

1页:5日课程介绍
2页:介绍反馈表单
3页:控制文字域的值
4页:文字域事件
5页:反馈表单处理器
6页:文字域的练习
7页:复选框
8页:单选框
9页:选单
10页:在选单中应用onchange命令



通过改变文字域的值就可实现这种奇妙的变换。表单编码:

<form name="form_two">

<textarea name="the_textarea" rows=10 cols=60>

Mouse over below to see the first verse of

The Webmonkey song, adapted from

"I Wanna Be Like You" (The Monkey Song)

from Walt Disney's The Jungle Book

written by Richard M. Sherman and Robert B. Sherman

</textarea>

</form>

注意该表单有一个名字:form_two,,并且文字区也有一个名字:
the_textarea

其链接和文字域的设定方法基本相同: